<template>
  <div style="display: flex">
    <el-input v-model="queryStr" />
    <el-button class="p-btn" type="primary" @click="clickSearch">搜索</el-button>
  </div>
</template>

<script setup>
import { ref } from "vue";
const queryStr = ref("");

async function clickSearch() {
  const matchedFiles = window.fileConfig.filter(({ searchParam1, searchParam2 }) => {
    return (searchParam1 && searchParam1 === queryStr.value) || (searchParam2 && searchParam2 === queryStr.value)
  });

  if (matchedFiles.length) {
    window.open(`/files/${matchedFiles[0].filename}`);
  } else {
    ElMessage.error("无搜索结果");
  }
}
</script>

<style scoped>
.p-btn{
  margin-left: 10px;
  width: 100px;
}
</style>
